package com.example.kotlineventtracker

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.kotlineventtracker.databinding.ActivityEventInfoBinding

import com.example.kotlineventtracker.view.EventAdapter
import com.example.kotlineventtracker.view.EventInfoAdapter
import com.example.kotlineventtracker.viewmodel.EventInfoViewModel
import com.example.kotlineventtracker.viewmodel.EventViewModel

class EventInfoActivity : AppCompatActivity() {
    private lateinit var binding: ActivityEventInfoBinding
    private val viewModel: EventInfoViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityEventInfoBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val eventId = intent.getStringExtra("eventId")
        val moduleDesc = intent.getStringExtra("moduleDesc")
        val eventType = intent.getStringExtra("eventType")
        if (eventId != null) {
            binding.eventId.text = "模块ID: ${eventId}"
            binding.moduleDesc.text = "模块名称: ${moduleDesc}"
        }

        val adapter = EventInfoAdapter(emptyList())
        binding.tableView.layoutManager = LinearLayoutManager(this)
        binding.tableView.adapter = adapter

        viewModel.events.observe(this, Observer { events ->
            binding.tableView.adapter = EventInfoAdapter(events)
        })

        if (eventId != null &&eventType != null) {
            if (eventType=="1"){
                viewModel.loadEventInfo(eventId,"clickbutton")
            }
            else {
                viewModel.loadEventInfo(eventId,"moduleExpose")
            }
        }
    }
}